package net.muchine.test.ddd.domain;

import org.springframework.beans.factory.annotation.Configurable;

import net.muchine.test.ddd.EntryPoint;
import net.muchine.test.ddd.domain.order.Order;

@Configurable(preConstruction=true)
public class Customer {
	private Long id;
	private String customerNumber;
	private String name;
	private String address;
	private long mileage;
	private Money limitPrice;
	
	public Customer() {}
	
	public Customer(String customerNumber, String name, String address, long limitPrice) {
		this.customerNumber = customerNumber;
		this.name = name;
		this.address = address;
		this.limitPrice = new Money(limitPrice);
	}
	
	public void purchase(long price) {
		this.mileage += price * 0.01;
	}
	
	public boolean isPossibleToPayWithMileage(long price) {
		return mileage > price;
	}
	
	public boolean payWithMileage(long price) {
		if (!this.isPossibleToPayWithMileage(price)) return false;
		
		this.mileage -= price;
		return true;
	}

	public Long getId() {
		return id;
	}

	public long getMileage() {
		return mileage;
	}

	public Money getLimitPrice() {
		return limitPrice;
	}

	public Order newOrder(String orderId) {
		return Order.order(orderId, this);
	}
	
	public boolean isExceedLimitPrice(Money money) {
		return money.isGreaterThan(limitPrice);
	}
}
